package hadoop.mapreduce.mapjoin;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class TableDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException, URISyntaxException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(TableDriver.class);
        job.setMapperClass(TableMapper.class);

        //MT输出结果
        job.setMapOutputKeyClass(TableBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        //整个mapper reduce程序的输出结果,没有reduce的时候就是mapper的输出
        job.setOutputKeyClass(TableBean.class);
        job.setOutputValueClass(NullWritable.class);

        //将文件加载到缓存中,可以放多个文件
        job.addCacheFile(new URI("file:///C:/tmp/join/pd.txt"));
        //不需要reduce,设置0
        job.setNumReduceTasks(0);

        FileInputFormat.setInputPaths(job,new Path("C:\\tmp\\join\\order.txt"));
        FileOutputFormat.setOutputPath(job,new Path("C:\\tmp\\aa"));

        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);
    }
}
